//
//  BRReportLostViewController.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/10/8.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRReportLostViewController.h"
#import "BRPaymentViewController.h"
#import "GXJWebViewController.h"

@interface BRReportLostViewController ()
{
    UIButton *_policyBtn;
    QMUIButton *_submitBtn;
}
@property (nonatomic,strong) BRLostSumModel *dtoLostAmount;

@end

@implementation BRReportLostViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUI];
}

/// 确认报失
- (void)confirmLost {

    [self requestLostPrice];
   
}

- (void)requestLostPrice {
    
     
//    [[BRRequestManager shared] GET:[BRAPI lostSum:self.dto.orderNo] params:@{} succeed:^(NSDictionary * _Nonnull dataDict, NSInteger respCode) {
//        
//        self.dtoLostAmount = [BRLostSumModel mj_objectWithKeyValues:dataDict[@"data"]];
//        
//        if (self.dtoLostAmount.money.floatValue != 0) {
//            
//            
//            
//        }else {
//            
//            
//        }
//        
//    } failed:^(NSInteger code, NSString * _Nonnull errMsg) {
//            
//    }];
    [self toPayLost];
    
}

- (void)toPayLost {
    
    
//    self.dto.money =
    
    BRPaymentViewController *payVC = [[BRPaymentViewController alloc] init];
    
    payVC.amount = self.dto.billing.penaltyAmount;
    payVC.payType = BRPAY_LOST;
    payVC.dto = self.dto;
    [self.navigationController pushViewController:payVC animated:YES];
}

- (void)clickPolicyBtn:(UIControl *)btn {
    _policyBtn.selected = !_policyBtn.selected;
    _submitBtn.enabled = _policyBtn.selected;
}

- (void)toPolicy {
    NSString *url = USERManager.termsOfUse;
    NSString *titleStr = Localized(@"set_terms");
    url = [NSString stringWithFormat:@"%@?lang=%@",url,[BRLanguageManager share].language];
    GXJWebViewController *webView = [[GXJWebViewController alloc] init];
    webView.url = url ;
    [webView initWhiteBarWithTitle:titleStr isBack: YES];
    webView.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:webView animated:YES completion:nil];
}

#pragma mark - SET UI --
- (void)setUI {
    
    [self br_createTop:Localized(@"home_reportLost")];
    
    UIView *submitView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - (kSafeAreaBottomHeight + 82), kScreenWidth, (kSafeAreaBottomHeight + 82) )];
    submitView.backgroundColor = UIColor.qd_backgroundColor;
    [self.view addSubview:submitView];
    [submitView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.bottom.offset(0);
    }];
    
    UIStackView *stack = [[UIStackView alloc] init];
    stack.axis = UILayoutConstraintAxisVertical;
    stack.spacing = 12;
    [submitView addSubview:stack];
    [stack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(12);
        make.left.offset(28);
        make.bottom.offset(-(12 + kSafeAreaBottomHeight));
        make.right.offset(-28);
    }];
    
    QMUIButton *submitBtn = [BRToolsView br_btnBGImg:Localized(@"home_reportLostConfirm")];
    
    [submitBtn addTarget:self action:@selector(confirmLost) forControlEvents:UIControlEventTouchUpInside];
    _submitBtn = submitBtn;
   
    UIImageView *lostImg = [[UIImageView alloc] init];
    lostImg.image = UIImageMake(@"home_lostEmj");
    [self.view addSubview:lostImg];
    [lostImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(85);
        make.top.offset(56 + kSafeAreaTopHeight);
        make.centerX.equalTo(self.view);
    }];
    
    NSString *text = [NSString stringWithFormat:Localized(@"home_lostText"),[BRPayManager br_amount:self.dto.billing.penaltyAmount]];
    QMUILabel *titleL = [BRToolsView br_label:text textColor:UIColorMakeWithHex(@"#889DBB") font:[UIFont fontS:17]];
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.numberOfLines = 0;
    [self.view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(kMarginLR2);
        make.right.equalTo(self.view).offset(-kMarginLR2);
        make.top.equalTo(lostImg.mas_bottom).offset(28);
    }];
    
    // 协议 -------------
    UIView *agreeBG = [[UIView alloc] init];
    
    YYLabel *agreeMsg = [YYLabel new];
    agreeMsg.font = [UIFont br_fontM:11];
    agreeMsg.numberOfLines = 0;
    agreeMsg.preferredMaxLayoutWidth = kScreenWidth - 100;//100
    agreeMsg.textAlignment = NSTextAlignmentLeft;
    [agreeBG addSubview:agreeMsg];
    [agreeMsg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(40);
        make.right.offset(0);
        make.bottom.top.offset(0);
        make.height.mas_greaterThanOrEqualTo(16);
    }];
    WS(weakSelf);
    NSString *terms = Localized(@"login_termOfUse");
    NSString *agreeStr = [NSString stringWithFormat:Localized(@"login_agreeTo"),terms,@""];
    agreeStr = [agreeStr stringByReplacingOccurrencesOfString:@"&" withString:@""];
    
    NSMutableAttributedString *agreeAttStr = [[NSMutableAttributedString alloc] initWithString:agreeStr];
    [agreeMsg sizeToFit];
    NSRange rangStr = [agreeStr rangeOfString:terms];
    [agreeAttStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:rangStr];
    UIColor *titleColor = UIColor.qd_titleTextColor2;
    agreeAttStr.yy_color = titleColor;
    agreeAttStr.yy_font = [UIFont br_fontM:10];
    [agreeAttStr yy_setTextHighlightRange:rangStr color: titleColor backgroundColor:UIColor.whiteColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
        [weakSelf toPolicy];
        NSLog(@"0");
    }];
    agreeMsg.attributedText = agreeAttStr;
    
    UIButton *policyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [policyBtn setImage:[UIImage imageNamed:@"pay_undefault"] forState:UIControlStateNormal];
    [policyBtn setImage:[UIImage imageNamed:@"pay_default"] forState:UIControlStateSelected];
    [agreeBG addSubview:policyBtn];
    [policyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(16);
        make.top.equalTo(agreeMsg.mas_top).offset(0);
        make.right.equalTo(agreeMsg.mas_left).offset(-8);
    }];
    
    policyBtn.userInteractionEnabled = NO;
    policyBtn.selected = YES;
    _policyBtn = policyBtn;
    
    [stack addArrangedSubview:agreeBG];
    [stack addArrangedSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(52);
    }];
    
    UIControl *btn = [[UIControl alloc] init];
    [submitView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(policyBtn);
        make.width.height.mas_equalTo(50);
        make.centerY.equalTo(policyBtn);
    }];
    [btn addTarget:self action:@selector(clickPolicyBtn:) forControlEvents:UIControlEventTouchUpInside];
}



@end

@implementation BRLostSumModel



@end
